@echo off
echo ========================================
echo 业务流程端到端测试
echo ========================================

echo 等待服务启动...
timeout /t 10 /nobreak >nul

echo.
echo ========================================
echo 场景1: 用户注册并登录
echo ========================================

echo 步骤1: 用户注册
set /a USER_ID=0
for /f "tokens=*" %%i in ('curl -s -X POST http://localhost:8080/api/users/register -H "Content-Type: application/json" -d "{\"username\":\"student1\",\"email\":\"student1@example.com\",\"password\":\"password123\"}"') do (
    echo 注册响应: %%i
    set USER_ID=1
)

echo.
echo 步骤2: 用户登录获取Token
for /f "tokens=*" %%i in ('curl -s -X POST http://localhost:8080/api/users/login -H "Content-Type: application/json" -d "{\"username\":\"student1\",\"password\":\"password123\"}"') do (
    echo 登录响应: %%i
    set TOKEN=%%i
)

echo.
echo ========================================
echo 场景2: 创建课程和练习
echo ========================================

echo 步骤3: 创建课程
set /a COURSE_ID=0
for /f "tokens=*" %%i in ('curl -s -X POST http://localhost:8080/api/courses -H "Content-Type: application/json" -d "{\"title\":\"Java编程基础\",\"description\":\"学习Java编程基础知识\",\"instructor\":\"张老师\"}"') do (
    echo 创建课程响应: %%i
    set COURSE_ID=1
)

echo.
echo 步骤4: 创建练习
set /a EXERCISE_ID=0
for /f "tokens=*" %%i in ('curl -s -X POST http://localhost:8080/api/exercises -H "Content-Type: application/json" -d "{\"title\":\"Java基础练习\",\"description\":\"Java变量和数据类型练习\",\"courseId\":1}"') do (
    echo 创建练习响应: %%i
    set EXERCISE_ID=1
)

echo.
echo ========================================
echo 场景3: 学习进度跟踪
echo ========================================

echo 步骤5: 开始学习课程
for /f "tokens=*" %%i in ('curl -s -X POST http://localhost:8080/api/progress -H "Content-Type: application/json" -d "{\"userId\":1,\"courseId\":1,\"progress\":25}"') do (
    echo 开始学习响应: %%i
)

echo.
echo 步骤6: 更新学习进度
for /f "tokens=*" %%i in ('curl -s -X PUT http://localhost:8080/api/progress/1 -H "Content-Type: application/json" -d "{\"userId\":1,\"courseId\":1,\"progress\":75}"') do (
    echo 更新进度响应: %%i
)

echo.
echo 步骤7: 查看学习进度
for /f "tokens=*" %%i in ('curl -s -X GET http://localhost:8080/api/progress/1') do (
    echo 学习进度: %%i
)

echo.
echo ========================================
echo 场景4: 数据查询验证
echo ========================================

echo 步骤8: 查看所有课程
echo 课程列表:
curl -s -X GET http://localhost:8080/api/courses

echo.
echo 步骤9: 查看所有练习
echo 练习列表:
curl -s -X GET http://localhost:8080/api/exercises

echo.
echo 步骤10: 查看所有用户
echo 用户列表:
curl -s -X GET http://localhost:8080/api/users

echo.
echo ========================================
echo 业务流程测试完成！
echo ========================================

echo 📋 测试验证点:
echo ✅ 用户注册和登录功能正常
echo ✅ 课程创建功能正常
echo ✅ 练习创建功能正常
echo ✅ 学习进度跟踪功能正常
echo ✅ 数据查询功能正常
echo.

echo 🔍 查看数据库数据:
echo docker exec -it microservices-mysql-1 mysql -uroot -proot123 -e "USE coursehub; SELECT * FROM users; SELECT * FROM courses; SELECT * FROM exercises; SELECT * FROM learning_progress;"
echo.

pause
